#! /bin/bash

DATAX_HOME=/opt/module/datax

#DataX导出路径不允许存在空文件，该函数作用为清理空文件
handle_export_path(){
  for i in `hadoop fs -ls -R $1 | awk '{print $8}'`; do
    hadoop fs -test -z $i
    if [[ $? -eq 0 ]]; then
      echo "$i文件大小为0，正在删除"
      hadoop fs -rm -r -f $i
    fi
  done
}

#数据导出
export_data() {
  datax_config=$1
  export_dir=$2
  handle_export_path $export_dir
  $DATAX_HOME/bin/datax.py -p"-Dexportdir=$export_dir" $datax_config
}

case $1 in
  "all")
    export_data /opt/module/datax/job/export/edu_import.ads_trade_by_province.json /warehouse/edu2077/ads/ads_trade_by_province
    export_data /opt/module/datax/job/export/edu_import.ads_trade_payment.json /warehouse/edu2077/ads/ads_trade_payment
    export_data /opt/module/datax/job/export/edu_import.ads_trade_by_category.json /warehouse/edu2077/ads/ads_trade_by_category
    export_data /opt/module/datax/job/export/edu_import.ads_trade_by_subject.json /warehouse/edu2077/ads/ads_trade_by_subject
    export_data /opt/module/datax/job/export/edu_import.ads_trade_by_course.json /warehouse/edu2077/ads/ads_trade_by_course
    export_data /opt/module/datax/job/export/edu_import.ads_course_comment.json /warehouse/edu2077/ads/ads_course_comment
    export_data /opt/module/datax/job/export/edu_import.ads_audition_category_by_tm.json /warehouse/edu2077/ads/ads_audition_category_by_tm
    export_data /opt/module/datax/job/export/edu_import.ads_audition_subject_by_tm.json /warehouse/edu2077/ads/ads_audition_subject_by_tm
    export_data /opt/module/datax/job/export/edu_import.ads_audition_course_by_tm.json /warehouse/edu2077/ads/ads_audition_course_by_tm
    export_data /opt/module/datax/job/export/edu_import.ads_traffic_stats_by_source.json /warehouse/edu2077/ads/ads_traffic_stats_by_source
    export_data /opt/module/datax/job/export/edu_import.ads_page_path.json /warehouse/edu2077/ads/ads_page_path
    export_data /opt/module/datax/job/export/edu_import.ads_traffic_order_by_sc.json /warehouse/edu2077/ads/ads_traffic_order_by_sc
    export_data /opt/module/datax/job/export/edu_import.ads_user_change.json /warehouse/edu2077/ads/ads_user_change
    export_data /opt/module/datax/job/export/edu_import.ads_user_retention.json /warehouse/edu2077/ads/ads_user_retention
    export_data /opt/module/datax/job/export/edu_import.ads_user_stats.json /warehouse/edu2077/ads/ads_user_stats
    export_data /opt/module/datax/job/export/edu_import.ads_user_action.json /warehouse/edu2077/ads/ads_user_action
	export_data /opt/module/datax/job/export/edu_import.ads_new_order_user_stats.json /warehouse/edu2077/ads/ads_new_order_user_stats
	export_data /opt/module/datax/job/export/edu_import.ads_generation_order_user_count.json /warehouse/edu2077/ads/ads_generation_order_user_count
	export_data /opt/module/datax/job/export/edu_import.ads_video_stats_by_course.json /warehouse/edu2077/ads/ads_video_stats_by_course
	export_data /opt/module/datax/job/export/edu_import.ads_video_stats_by_all.json /warehouse/edu2077/ads/ads_video_stats_by_all
	export_data /opt/module/datax/job/export/edu_import.ads_chapter_user_avg_by_course.json /warehouse/edu2077/ads/ads_chapter_user_avg_by_course
	export_data /opt/module/datax/job/export/edu_import.ads_chapter_play_rate.json /warehouse/edu2077/ads/ads_chapter_play_rate
	export_data /opt/module/datax/job/export/edu_import.ads_course_play_rate.json /warehouse/edu2077/ads/ads_course_play_rate
  ;;
esac